package edu.gdkm.dao;

import edu.gdkm.pojo.User;
import org.apache.ibatis.annotations.*;
import java.util.List;

public interface UserDAO {
    @Select("SELECT id, username, password, email, phone, user_type, avatar, status, create_time, update_time FROM user WHERE id = #{id}")
    User selectById(Long id);

    @Select("SELECT id, username, password, email, phone, user_type, avatar, status, create_time, update_time FROM user")
    List<User> selectAll();

    @Insert("INSERT INTO user(username, password, email, phone, user_type, avatar, status, create_time, update_time) " +
            "VALUES(#{username}, #{password}, #{email}, #{phone}, #{userType}, #{avatar}, #{status}, #{createTime}, #{updateTime})")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    int insert(User user);

    @Update("UPDATE user SET username = #{username}, password = #{password}, email = #{email}, phone = #{phone}, " +
            "user_type = #{userType}, avatar = #{avatar}, status = #{status}, update_time = #{updateTime} WHERE id = #{id}")
    int update(User user);

    @Delete("DELETE FROM user WHERE id = #{id}")
    int deleteById(Long id);

    @Select("SELECT id, username, password, email, phone, user_type, avatar, status, create_time, update_time FROM user WHERE username = #{username}")
    User selectByUsername(String username);

    @Select("SELECT id, username, password, email, phone, user_type, avatar, status, create_time, update_time FROM user WHERE email = #{email}")
    User selectByEmail(String email);
}
